# -*- coding: utf-8 -*-
from django.forms import model_to_dict
import xadmin
import json
from .models import *
from invoice.models import *
from organization.models import Store


class PageCustomAdmin(object):
    base_template = 'chart.html'
    hidden_menu = True

    def get_context(self):
        context = super(PageCustomAdmin, self).get_context()
        # 不同于插件，view类只能重载而不能截获

        chart_options = {
            "chart": {
                "type": "bubble",
                "zoomType": "xy",
            },
            "title": {
                "text": "Highcharts 气泡图",
            },
            "series": [
                {
                    "name": "数据列 1",
                    # 每个气泡包含三个值，x，y，z；其中x，y用于定位，z用于计算气泡大小
                    "data": [[97, 36, 79], [94, 74, 60], [68, 76, 58], [64, 87, 56], [68, 27, 73], [74, 99, 42],
                             [7, 93, 87],
                             [51, 69, 40], [38, 23, 33], [57, 86, 31]]
                },
                {
                    "name": "数据列 2",
                    "data": [[25, 10, 87], [2, 75, 59], [11, 54, 8], [86, 55, 93], [5, 3, 58], [90, 63, 44],
                             [91, 33, 17],
                             [97, 3, 56], [15, 67, 48], [54, 25, 81]]
                },
                {
                    "name": "数据列 3",
                    "data": [[47, 47, 21], [20, 12, 4], [6, 76, 91], [38, 30, 60], [57, 98, 64], [61, 17, 80],
                             [83, 60, 13],
                             [67, 78, 75], [64, 12, 10], [30, 77, 82]]
                }]
        }
        context["chart_options"] = chart_options

        return context

    def get(self, request, *args, **kwargs):
        # 当启用import_export_args时，可以在这里编写处理上传文件的代码
        print('request.path', request.path)
        return super(PageCustomAdmin, self).get(request, *args, **kwargs)


class SaleAlongTimeAdmin(object):
    base_template = 'custom_sale_along_time.html'

    def get_context(self):
        context = super(SaleAlongTimeAdmin, self).get_context()
        # 不同于插件，view类只能重载而不能截获
        stores = Store.objects.filter(is_own="00")
        context.update({
            "stores": stores,
        })
        return context

    def get(self, request, *args, **kwargs):
        # 当启用import_export_args时，可以在这里编写处理上传文件的代码
        print('request.path', request.path)
        return super(SaleAlongTimeAdmin, self).get(request, *args, **kwargs)


class SalePriceIOAdmin(object):
    base_template = 'custom_sale_price_io.html'

    def get_context(self):
        context = super(SalePriceIOAdmin, self).get_context()
        # 不同于插件，view类只能重载而不能截获
        return context

    def get(self, request, *args, **kwargs):
        # 当启用import_export_args时，可以在这里编写处理上传文件的代码
        print('request.path', request.path)
        return super(SalePriceIOAdmin, self).get(request, *args, **kwargs)


class SalePeriodAdmin(object):
    base_template = 'custom_sale_period.html'

    def get_context(self):
        context = super(SalePeriodAdmin, self).get_context()
        # 不同于插件，view类只能重载而不能截获
        stores = [ store for store in Store.objects.filter(is_own="00")]
        context.update({
            "stores": stores,
            "store_selector_init": random.choice(stores)
        })
        return context

    def get(self, request, *args, **kwargs):
        # 当启用import_export_args时，可以在这里编写处理上传文件的代码
        print('request.path', request.path)
        return super(SalePeriodAdmin, self).get(request, *args, **kwargs)


class SaleLabelAdmin(object):
    base_template = 'custom_sale_label.html'

    def get_context(self):
        context = super(SaleLabelAdmin, self).get_context()
        # 不同于插件，view类只能重载而不能截获
        stores = [ store for store in Store.objects.filter(is_own="00")]
        context.update({
            "stores": stores,
            "store_selector_init": random.choice(stores)
        })
        return context

    def get(self, request, *args, **kwargs):
        # 当启用import_export_args时，可以在这里编写处理上传文件的代码
        print('request.path', request.path)
        return super(SaleLabelAdmin, self).get(request, *args, **kwargs)


class InventoryAdmin(object):
    base_template = 'custom_inventory_along_time.html'

    def get_context(self):
        context = super(InventoryAdmin, self).get_context()
        # 不同于插件，view类只能重载而不能截获
        stores = [ store for store in Store.objects.filter(is_own="00")]
        context.update({
            "stores": stores,
            "store_selector_init": random.choice(stores)
        })
        return context

    def get(self, request, *args, **kwargs):
        # 当启用import_export_args时，可以在这里编写处理上传文件的代码
        print('request.path', request.path)
        return super(InventoryAdmin, self).get(request, *args, **kwargs)


class ClerkPerformanceAdmin(object):
    base_template = 'custom_clerk_performance.html'

    def get_context(self):
        context = super(ClerkPerformanceAdmin, self).get_context()
        # 不同于插件，view类只能重载而不能截获
        stores = [ store for store in Store.objects.filter(is_own="00")]
        context.update({
            "stores": stores,
            "store_selector_init": random.choice(stores)
        })
        return context

    def get(self, request, *args, **kwargs):
        # 当启用import_export_args时，可以在这里编写处理上传文件的代码
        print('request.path', request.path)
        return super(ClerkPerformanceAdmin, self).get(request, *args, **kwargs)


class ExpenseAlongTimeAdmin(object):
    base_template = 'custom_expense_along_time.html'

    def get_context(self):
        context = super(ExpenseAlongTimeAdmin, self).get_context()
        # 不同于插件，view类只能重载而不能截获
        stores = [ store for store in Store.objects.filter(is_own="00")]
        context.update({
            "stores": stores,
            "store_selector_init": random.choice(stores)
        })
        return context

    def get(self, request, *args, **kwargs):
        # 当启用import_export_args时，可以在这里编写处理上传文件的代码
        print('request.path', request.path)
        return super(ExpenseAlongTimeAdmin, self).get(request, *args, **kwargs)


xadmin.site.register(PageCustom, PageCustomAdmin)
xadmin.site.register(SaleAlongTime, SaleAlongTimeAdmin)
xadmin.site.register(SalePriceIO, SalePriceIOAdmin)
xadmin.site.register(SalePeriod, SalePeriodAdmin)
xadmin.site.register(SaleLabel, SaleLabelAdmin)
xadmin.site.register(Inventory, InventoryAdmin)
xadmin.site.register(ClerkPerformance, ClerkPerformanceAdmin)
xadmin.site.register(ExpenseAlongTime, ExpenseAlongTimeAdmin)

# 新建app后要在settings.py中注册
